<?php
require 'config_bd.php';
require 'csv.php';
require 'cle_encrypt.php';

$uname = $_REQUEST["name"];
$upass = $_REQUEST["pass"];
$utable = $_REQUEST["table"];

$db_conn = mysql_connect($hostname,$username ,$password);
mysql_set_charset('utf8',$db_conn); 
mysql_select_db($dbname);

if ( $uname != '' && $upass != '' ) 
{
    if ( $utable == 't102_fdt_invoice' )
	{ 
	  $sql = "CALL invoice_ftd_prc";
	  mysql_query($sql,$db_conn);
	}
	
	$sql = "SELECT * FROM " . $utable;
	$sql = $sql . " where EXISTS (SELECT * FROM t001_users where id = get_user_id( '" . $uname . "' , AES_ENCRYPT( '" . $upass . "' , '" . $cle_encrypt . "'))) " ;

	query_to_csv($db_conn, $sql, $utable . '.csv' , true);
}	
mysql_close($db_conn);
?>
